<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Use correct character set. -->
    <meta charset="utf-8">
    <!-- Tell IE to use the latest, best version. -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Hello World!</title>
    <script src="./cesium/Cesium.js"></script>
    <script src="./ext/testPrimitive.js"></script>

    <style>
        @import url(./cesium/Widgets/widgets.css);

        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #trailer {
            position: absolute;
            top: 10px;
            left: 20px;
            z-index: 10;
            visibility: hidden;
        }
    </style>
</head>

<body>
    <div id="cesiumContainer"></div>
    <div style="position: absolute;z-index: 10;top:20px;left: 20px;background-color: rgba(0, 0, 100,0.3)">
        <button type="button" onclick="add();">添加</button>
        <button type="button" onclick="clearPrimitive();">清除</button>
    </div>
    <div style="position: absolute;z-index: 10;top:50px;left: 20px;background-color: rgba(0, 0, 100,0.3)">
        <button type="button" onclick="addTest();">添加</button>
        <button type="button" onclick="clearTestPrimitive();">清除</button>
    </div>
    <div style="position: absolute;z-index: 10;top:80px;left: 20px;background-color: rgba(0, 0, 100,0.3)">
        <button type="button" onclick="addGroundPrimitive();">添加</button>
        <button type="button" onclick="clearGroundPrimitive();">清除</button>
    </div>
    <video id="trailer" muted="" autoplay="" loop="" crossorigin="" controls="">
        <source src="./source/video-diqiu.mp4" type="video/mp4">
        Your browser does not support the <code>video</code> element.
    </video>
    <script>
        var viewer = new Cesium.Viewer('cesiumContainer');
        var videoElm = document.getElementById("trailer");

        var tilesets = new Cesium.Cesium3DTileset({
            url: "http://localhost:8011/tileset.json",
        })
        viewer.scene.primitives.add(tilesets);
        tilesets.readyPromise.then(function (tileset) {
            viewer.camera.flyToBoundingSphere(tileset.boundingSphere);
        });


        var videoPrimitives = [];
        function addTest() {
            var scene = viewer.scene;
            var camera = viewer.camera;
            var orientation = VideoProjectionPrimitive.createOratetionFromCamera(camera);
            var frustum = camera.frustum;
            var origin = camera.position;
            var primitive = new VideoProjectionPrimitive({
                frustum: frustum,
                orientation: orientation,
                origin: origin,
                outline: true
            });
            scene.primitives.add(primitive);
            videoPrimitives.push(primitive)
        }

        function clearTestPrimitive() {
            videoPrimitives.forEach(x => {
                viewer.scene.primitives.remove(x);
            });
            videoPrimitives = [];
        }
    </script>

</body>

</html>